//引入请求函数
import request from "@/utils/request.ts";
import { requestHttp } from "@/utils/request.ts";

//引入类型约束
import type { userAddressType } from "./type.ts";

/**
 * 平台会员用户信息相关的api
 */



//获取平台会员用户信息(支持用户名或手机号 获取用户信息)
export const reqUserInfo = (userinfo:string) => {
    return requestHttp({
        url:"/reception/user",
        method:"get",
        params:{
            userinfo:userinfo
        }
    })
}

//更新平台会员的用户信息
export const reqUpdateUserInfo = (userInfo:any) => {
    return requestHttp({
        url:"/reception/user",
        method:"put",
        data:userInfo
    })
}

//添加一个平台新会员用户(注册新用户)
export const reqSaveUser = (userInfo:any) => {
    return requestHttp({
        url:"/reception/user",
        method:"post",
        data:userInfo
    })
}

//删除一个平台会员用户(用户注销账号)
export const reqDeleteUser = (username:string) => {
    return requestHttp({
        url:"/reception/user",
        method:"delete",
        params:{
            username:username
        }
    })
}


//获取平台会员用户的地址信息集合  userId:用户id
export const reqUserAddressList = (userId:number) => {
    return requestHttp({
        url:"/reception/user/address",
        method:"get",
        params:{
            userId:userId
        }
    })
}

//给平台会员用户添加一个收货地址信息
export const reqSaveAddress = (userAddress:userAddressType) => {
    return requestHttp({
        url:"/reception/user/address",
        method:"post",
        data:userAddress
    })
}

//给平台会员用户更新一条收货地址信息
export const reqUpdateAddress = (userAddress:userAddressType) => {
    return requestHttp({
        url:"/reception/user/address",
        method:"put",
        data:userAddress
    })
}

//给平台会员用户删除一条收货地址信息
export const reqDeleteAddress = (addressId:number) => {
    return requestHttp({
        url:"/reception/user/address",
        method:"delete",
        params:{
            addressId:addressId
        }
    })
}

//查询平台会员用户的一条地址信息，根据id
export const reqUserAddress = (addressId:number) => {
    return requestHttp({
        url:"/reception/user/address/id",
        method:"get",
        params:{
            addressId:addressId
        }
    })
}

//文件上传(用户上传更新头像)
export const reqUpdateAvatar = (formData:any) => {
    return requestHttp({
        url:"/uploadByBlob",
        method:"post",
        headers:{
            "Content-Type":"multipart/form-data"
        },
        data:formData
    })
}